package com.atguigu.userprofile.common.dao

import com.atguigu.userprofile.common.bean.TagInfo
import com.atguigu.userprofile.common.util.MySqlUtil

object TagInfoDAO {

  def  getTagInfoByTask(taskId:String): TagInfo ={

    var tagInfo:TagInfo=null
    val maybeTagInfo: Option[TagInfo] = MySqlUtil.queryOne(s"select * from tag_info where tag_task_id=$taskId" ,classOf[TagInfo],true)
    if(maybeTagInfo==None){
      throw  new RuntimeException(s" no tag for taskId :$taskId")
    }else{
      tagInfo=maybeTagInfo.get
    }
    tagInfo
  }

  def getTagInfoWithOn(): List[TagInfo] ={
    val sql =
      s"""
         |select tg.id,tag_code,tag_name,parent_tag_id,tag_type,
         |tag_value_type,tag_value_limit,tag_task_id,
         |tag_comment,tg.create_time
         |from tag_info tg ,task_info tk
         | where   tg.tag_task_id =tk.id   and  tk.task_status='1'
       """.stripMargin

    val tagInfoList: List[TagInfo] = MySqlUtil.queryList(sql,classOf[TagInfo],true)
    tagInfoList

  }

}
